package com.itheima.exception;

import java.util.Scanner;

public class Demo2 {

    public static void main(String[] args) {

        //异常的处理方式2：最外层捕获异常后，尝试重新修复
        System.out.println("程序开始");

        while (true) {
            try {
                double price = getPrice();
                System.out.println("成功设置定价：" + price);
                break;      //跳出循环
            } catch (Exception e) {
                System.out.println("价格输入有误，请重新输入");
            }
        }

        System.out.println("程序结束");
    }

    //接收用户输入的定价
    public static double getPrice() {

        Scanner sc = new Scanner(System.in);
        System.out.println("请输入商品定价：");
        double price = sc.nextDouble();
        return price;
    }
}
